package com.hot100;

import java.util.HashMap;
import java.util.Map;

@SuppressWarnings("all")
public class h003 {
    public static void main(String[] args) {
        System.out.println(lengthOfLongestSubstring("bbbbb"));
    }
    public static int lengthOfLongestSubstring(String s) {
        int max = 0,i=0,j=i+1,start=0;
        char[] chars = s.toCharArray();
        Map<Character, Integer> map = new HashMap<>();
        if (chars.length != 0) map.put(chars[0],0);
        while (j<chars.length) {
           if (map.containsKey(chars[j])){
               max = Math.max(max,j-i);
               i = map.get(chars[j])+1;
               i = Math.max(i,map.get(s.charAt(j)) + 1);
//               while (start<i){
//                 map.remove(chars[start++]);
//               }
           }
           map.put(chars[j],j);
           j++;
        }
        return  Math.max(j-i,max);
    }
}
